﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IFRS.Web;
using System.Data;
using IFRS.DataAccess.DAL;
using IFRS.Models;
using IFRS_Global;

public partial class IFRS_WIN04_3V : PageBase
{
    #region "---------- Property -----------"

    private readonly SPR_SUBSUDYLOAN dalSUBSUDYLOAN = new SPR_SUBSUDYLOAN();
    private SubsidyLoan subsidyloan = new SubsidyLoan();

    #endregion

    #region "---------- Events -----------"

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!(Page.IsPostBack || Page.IsCallback))
        {
            this.ViewMenu();
            BindControlData();
            SetErrorMessage();
            BindData();
        }
        else
            ClientScript.RegisterHiddenField("isPostBack", "1");
    }

    protected void btnCANCEL_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/IFRS/WIN04_1S.aspx");
    }

    #endregion

    #region "---------- Methods -----------"

    private void ViewMenu()
    {
        this.MenuTitleBar = Resources.ifrsResource.View + Resources.ifrsMenu.WIN04;
    }

    private void SetErrorMessage()
    {
    }

    private void BindControlData()
    {
        ddlCURRENCY_CODE.SetData(DDL_TYPE.Currency, "", false, true);

        SetControlReadOnly(form_control);
    }

    private void BindData()
    {
        int ID = Convert.ToInt32(Request.QueryString["id"].ToString());
        DataTable dtSubsidyLoan = dalSUBSUDYLOAN.SEARCH_BYID(ID);
        List<SubsidyLoan> SubsidyLoanList = new List<SubsidyLoan>();
        ConvertHelper.ConvertDataTableToObject(dtSubsidyLoan, SubsidyLoanList);
        if (dtSubsidyLoan.Rows.Count > 0)
        {
            hidSubsidyLoanID.Value = SubsidyLoanList[0].SubsidyLoanID.ToString();
            txtTRANSACTION_DATE.Text = SubsidyLoanList[0].TransactionDate.DateToString();
            txtACCOUNT_NO.Text = SubsidyLoanList[0].AccountNo;
            txtCOST_CENTER.Text = SubsidyLoanList[0].COST_CENTER_NM;
            hidCOST_CENTER.Value = SubsidyLoanList[0].CostCenter;
            txtGL_ACCOUNT.Text = SubsidyLoanList[0].GLAccountName;
            hidGL_ACCOUNT.Value = SubsidyLoanList[0].GLAccount;
            ddlCURRENCY_CODE.SelectedValue = SubsidyLoanList[0].CurrencyCode;
            txtREFERENCE_INTEREST_NM.Text = SubsidyLoanList[0].ReferenceInterestNM;
            hidREFERENCE_INTEREST_CD.Value = SubsidyLoanList[0].ReferenceInterestCD;
            txtADDITIONAL_INTEREST.Text = SubsidyLoanList[0].AdditionalInterest.ToString();
            chkIS_COMPENSATE.Checked = SubsidyLoanList[0].IsCompensate;
            txtIS_CONFIRMED.Text = (bool)SubsidyLoanList[0].IsConfirmed ? Resources.ifrsField.CONFIRM : Resources.ifrsField.CREATE;
        }
    }

    #endregion
}